// pages/personal/personal.js
import request from '../../utils/request'
let moveY = 0
let startY = 0
let distanceY = 0
Page({

  /**
   * 页面的初始数据
   */
  data: {
    coverTransform:'translateY(0rpx)',
    coverTransi:'',
    userInfo:{},
    recentPlayRecord:[],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let userInfo = wx.getStorageSync('userInfo')
    if(userInfo){
      this.setData({
        userInfo:JSON.parse(userInfo)
      })
      /* 个人播放记录 */
      this.getRecentPlay(this.data.userInfo.userId)
      
    }
  },
  async getRecentPlay(userId){
    let recentPlayRecordData = await request('/user/record',{uid:userId,type:0})
    let index = 0
    let recentPlayRecord = recentPlayRecordData.allData.slice(0,10).map(item=>{
      item.id = index++
      return item
    })
    this.setData({
      recentPlayRecord
    })
  },

  handleTouchStart(event){
    startY = event.touches[0].clientY;
    this.setData({
      coverTransi:''
    })
  },
  handleTouchMove(event){
    moveY = event.touches[0].clientY;
    distanceY = startY - moveY
    if(distanceY<=0){
      return;
    }
    if(distanceY>=90)(
      distanceY = 90
    )
    this.setData({
      coverTransform:`translateY(${distanceY}rpx)`
    })
  },
  handleTouchEnd(){
    this.setData({
      coverTransform:`translateY(0rpx)`,
      coverTransi:'transform 1s linear'
    })
  },
  toLogin(){
    wx.navigateTo({
      url: '/pages/login/login',
    })
  },
  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})